home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Brushes and Pens / LineCaps / LineCaps.cs next >
Encoding:
Text File  |  2001-01-15  |  1.3 KB  |  43 lines

  1. //---------------------------------------
  2. // LineCaps.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class LineCaps: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new LineCaps());
  14.      }
  15.      public LineCaps()
  16.      {
  17.           Text = "Line Caps";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {
  21.           Pen   penWide   = new Pen(Color.Gray, Font.Height);
  22.           Pen   penNarrow = new Pen(clr);
  23.           Brush brush     = new SolidBrush(clr);
  24.  
  25.           foreach (LineCap lc in Enum.GetValues(typeof(LineCap)))
  26.           {
  27.                grfx.DrawString(lc.ToString(), Font, brush, 
  28.                                Font.Height, Font.Height / 2);
  29.  
  30.                penWide.StartCap = lc;
  31.                penWide.EndCap   = lc;
  32.  
  33.                grfx.DrawLine(penWide, 2 * cx / 4, Font.Height, 
  34.                                       3 * cx / 4, Font.Height); 
  35.  
  36.                grfx.DrawLine(penNarrow, 2 * cx / 4, Font.Height, 
  37.                                         3 * cx / 4, Font.Height); 
  38.  
  39.                grfx.TranslateTransform(0, 2 * Font.Height);
  40.           }
  41.      }
  42. }
  43.